package com.housesales.interceptor;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * 
 * @ClassName: SessionInterceptor
 * @Description: session拦截
 * @author chenchao
 * @date 2013-12-6 上午07:06:15
 * 
 */
@Component
public class SessionInterceptor extends HandlerInterceptorAdapter {
	private List<String> uncheckUrls;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle
	 * (javax.servlet.http.HttpServletRequest,
	 * javax.servlet.http.HttpServletResponse, java.lang.Object)
	 */
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		String requestUrl = request.getRequestURI();
		if (uncheckUrls.contains(requestUrl)) {
			return true;
		} else if (((request.getSession().getAttribute("e_sn") != null) && !request
					.getSession().getAttribute("e_sn").toString().trim()
					.equals(""))) {
				return true;
		} else  if (((request.getParameter("e_sn") == null) || (request
				.getParameter("e_sn").trim().equals("")))) {
			return false;
		}else if (((request.getParameter("e_sn") != null) && (!request
				.getParameter("e_sn").trim().equals(""))) && requestUrl.equals("/houseSales/login.html")){
			return true;
		}
		return false;

	}

	/**
	 * @return the uncheckUrls
	 */
	public List<String> getUncheckUrls() {
		return uncheckUrls;
	}

	/**
	 * @param uncheckUrls
	 *            the uncheckUrls to set
	 */
	public void setUncheckUrls(List<String> uncheckUrls) {
		this.uncheckUrls = uncheckUrls;
	}
}
